home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / FinderFlocks / Shell / utils.cp < prev   
Encoding:
Text File  |  1996-06-22  |  2.6 KB  |  94 lines  |  [TEXT/CWIE]

  1. # include     "Shell.h"
  2.  
  3. extern  Boolean        gDoneFlag;
  4.  
  5.  
  6. /****************************************************
  7. Quickdraw Things...
  8. *****************************************************/
  9.  
  10.     
  11. /*------------------------------------------------------------------------
  12. NewPixImage()            Creates pix image and inits the fields of the pixmap...
  13. ------------------------------------------------------------------------*/
  14.  
  15. Boolean NewPixImage(PixMapHandle ThePix, Rect *TheRect, short dpth)
  16. {
  17.     Ptr                    ThePtr;
  18.     long                Offrowbytes, ptrsize;
  19.     
  20.     Offrowbytes    =(((dpth * (TheRect->right - TheRect->left)) + 15) / 16) * 2;
  21.     ptrsize = (TheRect->bottom - TheRect->top) * Offrowbytes;
  22.     ThePtr = NewPtr(ptrsize);
  23.     if(MemError() != noErr)
  24.         return(false);
  25.     
  26.     (**ThePix).baseAddr = ThePtr;
  27.     (**ThePix).rowBytes = Offrowbytes + 0x8000;
  28.     (**ThePix).bounds = *TheRect;
  29.     (**ThePix).pixelSize = dpth;
  30.     (**ThePix).cmpCount = 1;
  31.     (**ThePix).cmpSize = dpth;
  32.     return(true);
  33. }
  34.     
  35.  
  36. /*------------------------------------------------------------------------
  37. NewBitMap()            Creates bit image and inits the fields of the bitmap...
  38. ------------------------------------------------------------------------*/
  39.  
  40. Boolean NewBitMap(BitMap *TheMap, Rect *TheRect)
  41. {
  42.     long    rb;
  43.     Ptr        ba;
  44.     
  45.     rb = ((TheRect->right - TheRect->left + 15) / 16) * 2;
  46.     ba = NewPtr(rb * (TheRect->bottom - TheRect->top));
  47.     if( MemError() == noErr)
  48.     {
  49.         TheMap->rowBytes = rb;
  50.         TheMap->baseAddr = ba;
  51.         TheMap->bounds = *TheRect;
  52.         return(true);
  53.     }
  54.     else
  55.         return(false);
  56. }
  57.  
  58. /*-------------------------------------------------------------------------
  59. CenterRect()             Centers theRect over thePt...
  60. --------------------------------------------------------------------------*/
  61. void CenterRect(Rect *theRect, Point *thePt)
  62. {
  63.     /* First home theRect... */
  64.     
  65.     OffsetRect(theRect, -theRect->left, -theRect->top);
  66.     
  67.     /* ...then center it over thePt */
  68.     
  69.      
  70.     thePt->h = thePt->h - (theRect->right / 2);
  71.     thePt->v = thePt->v - (theRect->bottom / 2);
  72.     OffsetRect(theRect, thePt->h, thePt->v);
  73. }
  74.  
  75. /*-------------------------------------------------------------------------
  76. Center()             Returns the center of the rect
  77. --------------------------------------------------------------------------*/
  78. Point Center(Rect *theRect)
  79. {
  80.     Point        pt;
  81.         
  82.     pt.h = theRect->left + ((theRect->right - theRect->left) / 2);
  83.     pt.v = theRect->top + ((theRect->bottom - theRect->top) / 2);
  84.     return(pt);
  85. }
  86.  
  87. // Since we can't call GetMHandle to access the menu handle, we have to
  88. // look at the data stored in the control record
  89. MenuHandle GetPopUpMenuHandle(ControlHandle thisControl)
  90. {
  91.     popupPrivateDataHdl theMenuData = (popupPrivateDataHdl)(*thisControl)->contrlData;
  92.     return((*theMenuData)->mHandle);
  93. }
  94.